home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_3.5 / Examples / Icon / ConvertNewIcons.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-30  |  4.1 KB  |  210 lines

  1. /*
  2.  * $Id$
  3.  *
  4.  * :ts=4
  5.  *
  6.  * COPYRIGHT:
  7.  *
  8.  *   Unless otherwise noted, all files are Copyright (c) 1999 Amiga, Inc.
  9.  *   All rights reserved.
  10.  *
  11.  * DISCLAIMER:
  12.  *
  13.  *   This software is provided "as is". No representations or warranties
  14.  *   are made with respect to the accuracy, reliability, performance,
  15.  *   currentness, or operation of this software, and all use is at your
  16.  *   own risk. Neither Amiga nor the authors assume any responsibility
  17.  *   or liability whatsoever with respect to your use of this software.
  18.  *
  19.  */
  20.  
  21. #include <dos/dosextens.h>
  22. #include <dos/dosasl.h>
  23. #include <dos/rdargs.h>
  24.  
  25. #include <exec/memory.h>
  26.  
  27. #include <workbench/workbench.h>
  28.  
  29. #include <clib/exec_protos.h>
  30. #include <clib/utility_protos.h>
  31. #include <clib/dos_protos.h>
  32.  
  33. #include <pragmas/exec_sysbase_pragmas.h>
  34. #include <pragmas/utility_pragmas.h>
  35. #include <pragmas/dos_pragmas.h>
  36.  
  37. #include <string.h>
  38.  
  39. /****************************************************************************/
  40.  
  41. extern struct Library * SysBase;
  42. extern struct Library * DOSBase;
  43. extern struct Library * UtilityBase;
  44. extern struct Library * IconBase;
  45.  
  46. /****************************************************************************/
  47.  
  48. #include <workbench/icon.h>
  49. #include <clib/icon_protos.h>
  50. #include <pragmas/icon_pragmas.h>
  51.  
  52. /****************************************************************************/
  53.  
  54. #define OK (0)
  55. #define SAME (0)
  56.  
  57. /****************************************************************************/
  58.  
  59. #define MAX_PATH_LEN 1024
  60.  
  61. /****************************************************************************/
  62.  
  63. #define FIB_IS_DRAWER(fib)    ((fib)->fib_DirEntryType > 0)
  64. #define FIB_IS_FILE(fib)    ((fib)->fib_DirEntryType < 0)
  65.  
  66. /****************************************************************************/
  67.  
  68. int
  69. main(int argc,char **argv)
  70. {
  71.     struct RDArgs * rda = NULL;
  72.     struct AnchorPath * ap;
  73.     STRPTR buffer = NULL;
  74.     int result = RETURN_FAIL;
  75.     STRPTR * names = NULL;
  76.     BOOL matched = FALSE;
  77.     LONG error = OK;
  78.     STRPTR str;
  79.  
  80.     if(IconBase->lib_Version < 44)
  81.     {
  82.         Printf("Could not open icon.library V44\n");
  83.         goto out;
  84.     }
  85.  
  86.     rda = ReadArgs("FILES/A/M",(LONG *)&names,NULL);
  87.     if(rda == NULL)
  88.     {
  89.         error = IoErr();
  90.         goto out;
  91.     }
  92.  
  93.     ap = AllocVec(sizeof(*ap) + MAX_PATH_LEN,MEMF_ANY);
  94.     if(ap == NULL)
  95.     {
  96.         error = ERROR_NO_FREE_STORE;
  97.         goto out;
  98.     }
  99.  
  100.     buffer = AllocVec(MAX_PATH_LEN,MEMF_ANY);
  101.     if(buffer == NULL)
  102.     {
  103.         error = ERROR_NO_FREE_STORE;
  104.         goto out;
  105.     }
  106.  
  107.     while((error == OK) && (str = (*names++)) != NULL)
  108.     {
  109.         memset(ap,0,sizeof(*ap));
  110.  
  111.         ap->ap_BreakBits = SIGBREAKF_CTRL_C;    
  112.         ap->ap_Strlen = MAX_PATH_LEN;
  113.  
  114.         matched = TRUE;
  115.  
  116.         error = MatchFirst(str,ap);
  117.         if(error == OK)
  118.         {
  119.             if(FIB_IS_DRAWER(&ap->ap_Info))
  120.             {
  121.                 ap->ap_Flags |= APF_DODIR;
  122.  
  123.                 error = MatchNext(ap);
  124.                 ap->ap_Flags &= ~APF_DIDDIR;
  125.             }
  126.  
  127.             while(error == OK)
  128.             {
  129.                 int len;
  130.  
  131.                 strcpy(buffer,ap->ap_Buf);
  132.                 len = strlen(buffer);
  133.  
  134.                 error = MatchNext(ap);
  135.  
  136.                 if(len < strlen(".info") || Stricmp(&buffer[len - strlen(".info")],".info") != SAME)
  137.                 {
  138.                     struct DiskObject * icon;
  139.                     LONG why;
  140.  
  141.                     Printf("Getting icon for \"%s\"... ",buffer);
  142.                     Flush(Output());
  143.  
  144.                     icon = GetIconTags(buffer,
  145.                         ICONA_ErrorCode,&why,
  146.                     TAG_DONE);
  147.  
  148.                     if(icon != NULL)
  149.                     {
  150.                         Printf("writing it back... ");
  151.                         Flush(Output());
  152.  
  153.                         if(PutIconTags(buffer,icon,
  154.                             ICONPUTA_DropNewIconToolTypes,TRUE,
  155.                             ICONPUTA_NotifyWorkbench,TRUE,
  156.                             ICONA_ErrorCode,&why,
  157.                         TAG_DONE))
  158.                         {
  159.                             Printf("ok.\n");
  160.                         }
  161.  
  162.                         FreeDiskObject(icon);
  163.                     }
  164.  
  165.                     if(why != OK)
  166.                     {
  167.                         UBYTE errorString[100];
  168.                         int len;
  169.  
  170.                         Fault(why,NULL,errorString,sizeof(errorString));
  171.  
  172.                         len = strlen(errorString);
  173.                         while(len > 0 && errorString[len-1] == '\n')
  174.                             errorString[--len] = '\0';
  175.  
  176.                         Printf("failed (%s).\n",errorString);
  177.                     }
  178.                 }
  179.             }
  180.         }
  181.  
  182.         if(error == ERROR_NO_MORE_ENTRIES)
  183.             error = OK;
  184.  
  185.         MatchEnd(ap);
  186.         matched = FALSE;
  187.     }
  188.  
  189.     if(error == OK)
  190.         result = RETURN_OK;
  191.     else if (error == ERROR_BREAK)
  192.         result = RETURN_WARN;
  193.     else
  194.         result = RETURN_ERROR;
  195.  
  196.  out:
  197.  
  198.     if(matched)
  199.         MatchEnd(ap);
  200.  
  201.     FreeVec(ap);
  202.     FreeVec(buffer);
  203.     FreeArgs(rda);
  204.  
  205.     if(error != OK)
  206.         PrintFault(error,FilePart(argv[0]));
  207.  
  208.     return(result);
  209. }
  210.